'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 9_study_runable_life_listener.py
* @Time: 2025/7/27
* @All Rights Reserve By Brtc
'''
from time import sleep

from langchain_core.runnables import RunnableConfig, RunnableLambda
from langchain_core.tracers import Run


def on_start(run_obj:Run, config:RunnableConfig)->None:
    print("on_start")
    print("run_obj:", run_obj)
    print("config:", config)

def on_end(run_obj:Run, config:RunnableConfig)->None:
    print("on_end")
    print("run_obj:", run_obj)
    print("config:", config)

def on_error(run_obj:Run, config:RunnableConfig)->None:
    print("on_error")
    print("run_obj:", run_obj)
    print("config:", config)

runable = RunnableLambda(lambda x:sleep(x))
chain = runable.with_listeners(on_start=on_start, on_end=on_end, on_error=on_error)

chain.invoke(2, config={"configurable":{"name":"博小睿"}})
